package com.eunion.core.common;

import java.util.ArrayList;
import java.util.List;

/**
 * WEB 系统page类.
 * 
 * 
 * @version 2015-5-13
 */
public class Pager {

    private int curPage = 1; // 当前页

    private int nextPage = 1;// 下一页

    private int previousPage = 1;// 上一页

    private int pageSize = 5; // 每页多少行

    private int totalRow = 0; // 共多少行

    private int start = 0;// 当前页起始行

    private int end = 0;// 结束行

    private int totalPage = 0; // 共多少页

    @SuppressWarnings("rawtypes")
    private List<?> objLists = new ArrayList();

    public Pager() {
        this(1);
    }

    public Pager(int curPage) {
        super();
        this.curPage = curPage;
        calc();
    }

    public Pager(int curPage, int pageSize) {
        super();
        this.curPage = curPage;
        this.pageSize = pageSize;
        calc();
    }

    public int getCurPage() {
        return curPage;
    }

    private void calc() {
        if (totalRow <= 0) {
            totalRow = 0;
        }
        if (curPage < 1) {
            curPage = 1;
        }
        if (pageSize < 1) {
            pageSize = 5;
        }
        totalPage = totalRow / pageSize + (totalRow % pageSize > 0 ? 1 : 0);
        previousPage = (curPage > 1) ? (curPage - 1) : 1;
        nextPage = (totalPage < (curPage + 1)) ? totalPage : curPage + 1;
        start = pageSize * (curPage - 1);
        end = start + pageSize;
    }

    public void setCurPage(int curPage) {
        this.curPage = curPage;
        calc();
    }

    public int getStart() {
        return start;
    }

    public int getEnd() {

        return end;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
        calc();
    }

    public int getTotalRow() {
        return totalRow;
    }

    public void setTotalRow(int totalRow) {
        this.totalRow = totalRow;
        calc();
    }

    public int getTotalPage() {

        return this.totalPage;
    }

    public int getNextPage() {
        return nextPage;
    }

    public int getPreviousPage() {
        return previousPage;
    }

    public void setStart(int start) {
        this.start = start;
        calc();
    }

    public List<?> getObjLists() {
        return objLists;
    }

    public void setObjLists(List<?> objLists) {
        this.objLists = objLists;
    }

}
